package cn.yto.print.utils;

import cn.yto.print.enums.PluginRegistryEnum;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.util.UUID;

public class PluginVerisonUtil {

    private static final Logger logger = LoggerFactory.getLogger(PluginVerisonUtil.class);

    /**
     * 获取客户端版本信息
     */
    public static void sendAgentInfo(WebSocketSession socketSession, PluginRegistryEnum printScoketEnum) {
        JSONObject appInfoRequest = new JSONObject();
        switch (printScoketEnum) {
            case PDD:
                appInfoRequest.put("cmd", "getAppInfo");
                appInfoRequest.put("version", "1.0");
                appInfoRequest.put("requestID", UUID.randomUUID().toString().replaceAll("-", ""));
                break;
            case JD:
                appInfoRequest.put("orderType", "GET_Version");
                break;
            case DW:
                appInfoRequest.put("cmd", "getAppInfo");
                appInfoRequest.put("version", "1.0");
                appInfoRequest.put("requestID", UUID.randomUUID().toString().replaceAll("-", ""));
                break;
            case KS:
                appInfoRequest.put("cmd", "getClientInfo");
                appInfoRequest.put("version", "1.0");
                appInfoRequest.put("requestID", UUID.randomUUID().toString().replaceAll("-", ""));
                break;
            case WXSPH:
                appInfoRequest.put("command", "getAppInfo");
                appInfoRequest.put("version", "1.0");
                break;
            case AKC:
                appInfoRequest.put("esubrc", "getlocal");
                break;
            default:
                appInfoRequest.put("cmd", "getAgentInfo");
                appInfoRequest.put("version", "1.0");
                appInfoRequest.put("requestID", UUID.randomUUID().toString().replaceAll("-", ""));
                break;
        }

        try {
            socketSession.sendMessage(new TextMessage(appInfoRequest.toJSONString()));
        } catch (Exception e) {
            logger.error(printScoketEnum.getCode() + " plugin get version exception", e);
        }
    }

}
